package com.mioto.ld.module.device.controller;

import cn.hutool.core.util.StrUtil;
import com.mioto.ld.module.device.model.DeviceFunctionLogPagerVO;
import org.springframework.web.bind.annotation.*;
import com.mioto.ld.module.device.model.DeviceFunctionLog;
import com.mioto.ld.module.device.service.IDeviceFunctionLogService;
import com.mioto.ld.result.ResultData;
import com.mioto.ld.result.SystemTip;
import com.mioto.ld.component.BasePager;
import com.mioto.ld.exception.BasicException;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
 *
 * @author mioto
 * @date 2024-05-15 16:13:51
 */
@RestController
@RequestMapping("deviceFunctionLog")
@Api(tags = "设备功能执行记录管理")
public class DeviceFunctionLogController {
    @Resource
    private IDeviceFunctionLogService deviceFunctionLogService;

    @GetMapping("/pager")
    @ApiOperation(value="分页查询设备功能执行记录",response = DeviceFunctionLogPagerVO.class)
    public ResultData pager (HttpServletRequest request, Integer deviceId,String startTime,String endTime,BasePager basePager){
        PageHelper.startPage(basePager.getPage(), basePager.getRows(), basePager.getSortBy());
        List<DeviceFunctionLogPagerVO> list = deviceFunctionLogService.findPager(deviceId,startTime,endTime);
        PageInfo<DeviceFunctionLogPagerVO> pageInfo = new PageInfo<>(list);
        Map<String, Object> result = new HashMap<>(4);
        result.put("count", pageInfo.getTotal());
        result.put("list", pageInfo.getList());
        return ResultData.success(result);
    }
}